<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<meta name="layout" content="main"/>
<title>Página de Login</title>
</head>
<body>
  	${flash.message}
  	<h1>Notas da Disciplina: ${disciplina.nome}</h1>
  	<span id="disciplina" class="invisible">${disciplina.id}</span>
  	<table class="table table-hover table-striped" id="listaNotaAluno">
  		<thead>
  			<tr>
  				<th>Nome</th>
  				<th>Matricula</th>
  				<th>N1</th>
  				<th>N2</th>
  			</tr>
  		</thead>
  		<tbody>
		  	<g:each in="${listaAluno}" var="aluno">
		  		<tr>
	  				<td>${aluno.nome}</td>
	  				<td>${aluno.matricula}</td>
	  				<td><g:field type="text"  class="form-control" name="nota-${aluno.id}-1"/></td>
	  				<td><g:field type="text" name="nota-${aluno.id}-2"/></td>
  				</tr>
		  	</g:each>
	  	</tbody>
  	</table>
  
  <g:javascript>
  	carregarNota("${disciplina.id}");
  
  	$("#listaNotaAluno input").blur(function(){
  		var valor = $(this).val()
  		if(valor.length > 0){
	  		var ident = $(this).attr("id").split("-")
	  		var idAluno = ident[1]
	  		var unidade = ident[2]
	  		var disciplina = $("#disciplina").html()
	  		$.ajax({
	  			url: '/sisacad/nota/enviarNota',
	  			data: {aluno:idAluno,unidade:unidade,disciplina:disciplina,valor:valor},
	  			cache: false,
	  			type: 'POST'
	  		})
  		}
  	});
  	
  	function carregarNota(disciplina){
  		$.ajax({
  			url: '/sisacad/nota/carregar/'+disciplina,
	  		cache: false,
	  		type: 'POST',
	  		success: function(data){
	  			//console.info(data);
	  			for (var chave in data) {
				  if (data.hasOwnProperty(chave)) {
				  	$("#"+chave).val(data[chave]);
				    //console.info(chave + " -> " + data[chave]);
				  }
				}
	  		}
  		})
  	}
  </g:javascript>
</body>
</html>